<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('物料')"/>
	<th:block th:include="include :: layout-latest-css"/>
	<th:block th:include="include :: ztree-css"/>
	<style>
		[v-cloak] {
			display: none;
		}
	</style>
</head>
<body class="gray-bg">
<!--	<div class="ui-layout-west">-->
<!--		<div class="main-content">-->
<!--			<div class="box box-main">-->
<!--				<div class="box-header">-->
<!--					<div class="box-title">-->
<!--						<i class="fa icon-grid"></i> 物料分类-->
<!--					</div>-->
<!--					<div class="box-tools pull-right">-->
<!--						<a type="button" class="btn btn-box-tool menuItem" href="#" onclick="dept()" title="物料分类">-->
<!--							<i class="fa fa-edit"></i>-->
<!--						</a>-->
<!--						<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display: none">-->
<!--							<i class="fa fa-chevron-up"></i>-->
<!--						</button>-->
<!--						<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠">-->
<!--							<i class="fa fa-chevron-down"></i>-->
<!--						</button>-->
<!--						<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新">-->
<!--							<i class="fa fa-refresh"></i>-->
<!--						</button>-->
<!--					</div>-->
<!--				</div>-->
<!--				<div class="ui-layout-content">-->
<!--					<div id="tree" class="ztree"></div>-->
<!--				</div>-->
<!--			</div>-->
<!--		</div>-->
<!--	</div>-->
     <div class="container-div ui-layout-center">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<input type="hidden" id="itemTypeName" name="itemTypeName">
					<div class="select-list">
						<ul>
							<li>
								物料编码：<input type="text" name="itemCode"/>
							</li>
							<li>
								物料名称：
								<select name="itemName">
									<option value="">全部</option>
									<option v-for="(item, index) in itemNames" :key="index" :value="item" v-cloak>{{item}}</option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" @click="additem" shiro:hasPermission="system:itemInfo:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="system:itemInfo:edit">
					<i class="fa fa-edit"></i> 修改
				</a>
				<a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:itemInfo:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:itemInfo:export">
					<i class="fa fa-download"></i> 导出
            	</a>
				<a class="btn btn-primary" onclick="$.table.print()">
					<i class="fa fa-plus"></i> 打印
				</a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true" style="white-space: nowrap"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
	<th:block th:include="include :: layout-latest-js"/>
	<th:block th:include="include :: ztree-js"/>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:itemInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:itemInfo:remove')}]];
        var prefix = ctx + "system/itemInfo";

		var app = new Vue({
			el: '.container-div',
			data: {
				itemNames: []
			},
			methods: {
				additem() {
					localStorage.setItem('wltitle', 'xnz');
					var _url = $.table._option.createUrl;
					$.modal.open('新增物料', _url, '800', '500', null);
				},
				getItemNames(){
					var that = this;
					$.ajax({
						cache: true,
						type: "POST",
						url: "/system/itemInfo/findList",
						data: {},
						async: false,
						error: function(request){
							$.modal.alertError("系统错误");
						},
						success: function(data){
							var arr = [];
							for(var i = 0; i < data.rows.length; i++){
								if(arr.indexOf(data.rows[i].itemName) == -1){
									arr.push(data.rows[i].itemName);
								}
							}
							that.itemNames = arr;
						}
					});
				}
			},
			created(){
				this.getItemNames();
			}
		})

        $(function() {
			var panehHidden = false;
			if ($(this).width() < 769) {
				panehHidden = true;
			}
			$('body').layout({ initClosed: panehHidden, west__size: 185 });
			queryItemInfoList();
			queryItemTypeTree();
        });

        function queryItemInfoList(){
			var options = {
				url: prefix + "/findList",
				createUrl: prefix + "/add",
				updateUrl: prefix + "/edit/{id}",
				removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
				modalName: "物料",
				columns: [
					{
						checkbox: true
					},
					{
						field: 'itemId',
						title: '物料ID',
						align: 'center',
						visible: false
					},
					{
						field: 'itemCode',
						title: '物料编码',
						align: 'center'
					},
					{
						field: 'itemName',
						title: '物料名称',
						align: 'center'
					},
					{
						field: 'sort',
						title: '分类',
						align: 'center',
						formatter: function(value, row, index){
							if(value == 1){
								return "钢材";
							}else{
								return "铜材";
							}
						}
					},
					{
						field: 'baseUnit',
						title: '基本单位',
						align: 'center'
					},
					{
						field: 'unit',
						title: '采购单位',
						align: 'center'
					},
					{
						field: 'boxAutomatic',
						title: '自动采购',
						align: 'center'
					},
					{
						field: 'boxStock;',
						title: '过账检验库存',
						align: 'center'
					},
					{
						field: 'rounding',
						title: '采购舍入值',
						align: 'center'
					},
					{
						field: 'userCode',
						title: '采购人编码',
						align: 'center'
					},
					{
						field: 'taxation',
						title: '课税',
						align: 'center'
					},
					{
						field: 'profit',
						title: '利润中心',
						align: 'center'
					},
					{
						field: 'purchase',
						title: '采购组',
						align: 'center'
					},
					{
						field: 'census',
						title: '统计组',
						align: 'center'
					},
					{
						field: 'height',
						title: '高',
						align: 'center'
					},
					{
						field: 'max',
						title: '最大数量',
						align: 'center'
					},
					{
						field: 'min',
						title: '最小数量',
						align: 'center'
					},
					{
						field: 'time',
						title: '有效期',
						align: 'center'
					},
					{
						title: '操作',
						align: 'center',
						events: {
							'click .edit': function(e, value, rowData, index){
								var id = rowData.itemId;
								// var id = rowData.materialId;
								var _url = $.table._option.createUrl;
								localStorage.setItem(_url, id.toString());
								localStorage.setItem('wltitle', '编辑');
								$.modal.open('编辑物料', _url, '800', '500', null);
							}
						},
						formatter: function(value, row, index){
							var actions = [];
							actions.push('<a class="btn btn-success btn-xs edit ' + editFlag + '" href="#"><i class="fa fa-edit"></i>编辑</a> ');
							actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.itemId + '\')"><i class="fa fa-remove"></i>删除</a>');
							return actions.join('');
						}
					}
				]
			};
			$.table.init(options);
		}

		function queryItemTypeTree(){
			var url = ctx + "system/itemType/treeData";
			var options = {
				url: url,
				expandLevel: 3,
				onClick: zOnClick
			};
			$.tree.init(options);
			function zOnClick(event, treeId, treeNode){
				$("#itemTypeName").val(treeNode.name);
				$.table.search();
			}
		}

		$('#btnExpand').click(function(){
			$._tree.expandAll(true);
			$(this).hide();
			$('#btnCollapse').show();
		});

		$('#btnCollapse').click(function(){
			$._tree.expandAll(false);
			$(this).hide();
			$('#btnExpand').show();
		});

		$('#btnRefresh').click(function(){
			queryItemTypeTree();
		});

		/* 物料管理-分类 */
		function dept(){
			var url = ctx + "system/itemType";
			createMenuItem(url, "物料分类");
		}
    </script>
</body>
</html>
